package com.atguigu.springcloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @Author : 李红磊
 * @Date : 2021/05/25/23:28
 * @Description :
 */

@RestController
public class FlowLimitController {


    @GetMapping("/testA")
    public String testA(){
        System.out.println(Thread.currentThread().getName()+"\ttestA");
        return "----testA 测试RT";
    }

    @GetMapping("/testB")
    public String testB(){
        return "----testB";
    }

    @GetMapping("/testD")
    public String testD(){
       /* try {
            TimeUnit.MILLISECONDS.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName()+"\ttestD\t RT测试" );*/

        System.out.println("testD\t异常比例");
       int a=100/0;

        return "----testD";
    }



    @GetMapping("/testE")
    public String testE(){
        System.out.println("测试异常数量");
        int age=10/0;
        return "----testE";
    }

    @GetMapping("/testHotKey")
    @SentinelResource(value = "testHotKey",blockHandler = "deal_testHotKey")
    public String testHotKey(@RequestParam(value = "p1",required = false)String ps,
                             @RequestParam(value = "p2",required = false)String p2){

        return "testHotKey";
    }

    public String deal_testHotKey(String p1, String p2, BlockException exception){

        return "deal_testHotKey,o(╥﹏╥)o";

    }

}
